package com.fzn.spring5.testdemo;

import com.fzn.spring5.User;
import com.fzn.spring5.bean.Emp;
import com.fzn.spring5.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author fzn
 * @date 2022/2/20
 * @apiNote
 */
public class BeanTest {

    /**
     * 外部bean的操作
     */
    @Test
    public void testAdd(){
        // 1.加载spring的配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean2.xml");
        // 2.获取配置创建对象
        UserService userService = context.getBean("userService", UserService.class);
        System.out.println(userService);
        userService.add();
    }

    /**
     *内部bean的操作
     */
    @Test
    public void testAdd2(){
        // 1.加载spring的配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean3.xml");
        // 2.获取配置创建对象
        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);
        emp.add();
    }

    /**
     * 级联赋值
     */
    @Test
    public void testAdd3(){
        // 1.加载spring的配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean4.xml");
        // 2.获取配置创建对象
        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);
        emp.add();
    }

}
